package com.yimingkeji.apiversion.rest;

import com.yimingkeji.apiversion.config.ApiVersion;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Describe:
 * @Auther: zhenlong.yang
 * @Date: 2018/11/22 15:35
 */
@RestController
@RequestMapping("/api")
public class UserResource {

    @GetMapping("/user")
    public User findOne(){
        return new User().setId(0).setName("default");
    }

    @GetMapping("/user")
    @ApiVersion("1.0.0")
    public User findOne1(){
        return User.DEFAULT();
    }

    @GetMapping("/user")
    @ApiVersion("2.0.2")
    public User findOne2(){
        return new User().setId(2).setName("嘿嘿嘿");
    }

    @GetMapping("/v")
    public String subVersion(@RequestParam(defaultValue = "1.0.1") String v1, @RequestParam(defaultValue = "2.0.1")String v2){
        StringBuilder sb = new StringBuilder();
        sb.append("1.0.1 compare 1.0.0\n");
        sb.append("1.0.0".compareTo("1.0.1"));
        sb.append("\n-------------\n");
        sb.append("1.0.1 compare 1.0.9\n");
        sb.append("1.0.1".compareTo("1.0.9"));
        sb.append("\n---------res---------\n");
        sb.append("V1="+v1+" ,compare V2="+v2+"\n");
        sb.append(v1.compareTo(v2));
        return sb.toString();
    }

    @Data
    @Accessors(chain = true)
    public static class User{
        private int id = 1;
        private String name = "哈哈";

        public static User DEFAULT(){
            return new User();
        }
    }
}
